<head>
<script type="text/javascript" src="<?php echo base_url()?>uploadify/jquery-1.4.2.min.js"></script>
<script src="<?php echo base_url()?>images/js/qunit.js"></script>
<script src="<?php echo base_url()?>images/js/external/jquery.bgiframe-2.1.2.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.core.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.widget.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.mouse.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.button.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.draggable.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.position.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.resizable.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.ui.dialog.js"></script>
<script src="<?php echo base_url()?>images/js/ui/jquery.effects.core.js"></script>
<link rel="stylesheet" href="<?php echo base_url()?>images/js/themes/base/jquery.ui.all.css">
<style type="text/css">
.ui-dialog-titlebar,.ui-dialog-buttonpane,.color
	{
		border-style:solid;border-width:1px;border-color:gray;-moz-border-radius:3px;border-radius:3px;background:rgba(0,0,0,0.21);font-size:14px;color:white;
	}
	.dialog_class
	{
		border-style:solid;border-width:1px;border-color:gray;-moz-border-radius:3px;border-radius:3px;background:rgba(0,0,0,0.61);font-size:14px;color:white;
	}

</style>
</head>
<body id="body_id">
<!--copyContext-->
<div id="copyContext" title="Move Context">
	<p id="validation_copy" class="validateTips"></p>

	<form style="border-color:black">
	<fieldset style="border-style:hidden; padding-left:30px;color:white">
                <label for="new_copy_name">New Name:</label>
                <br/>
                <input type="text" id="new_copy_name"/>
                <br/>
                <label for="moveContext">Copy Context To:</label>
                <br/>
                <select id="sit_Id_copy" SIZE="10" style="width:280px">

                </select>
                <br /><br />
                <input id="type" name="type" type="radio" value="dublicate" >Duplicate
                <input id="type" name="type" type="radio" value="copy" checked="true" /> Copy
	</fieldset>
        </form>
</div>

<script type="text/javascript">
    var rec_contexts='<?php echo $contexts; ?>';
    var username='<?php echo $username; ?>';
    var selectedSitId='<?php echo $situation_id; ?>';
    var contexts=eval('(' + rec_contexts + ')');
    var global_context_id_selected='';
    //alert(contexts[0].name);
    document.getElementById("body_id").style.background = "url(<?php echo base_url()?>images/templete/<?php echo $back_img?>) no-repeat center center fixed";
    document.getElementById("body_id").style.backgroundSize ='cover';
    
    function show(id)
    {
        document.getElementById("o_"+id).style.visibility = 'visible';
    }
    function hide(id)
    {
     document.getElementById("o_"+id).style.visibility = 'hidden';
     document.getElementById(id).style.visibility = 'visible';
    }
    function copy(element)
    {
        global_context_id_selected=element;
        cutted_element=element;
        getAllSit_ddlist_copy();
        //var context_id_cuting='';
        $( "#copyContext" ).dialog( "open" );

    }
    function imgHover(id,Isrc)
    {
        if(document.getElementById(id)!=null)
            document.getElementById(id).src = '<?php echo base_url()?>images/'+Isrc;
    }
    function getAllSit_ddlist_copy()
    {
        var userEmail=username;
        var url='<?php echo base_url()?>home/getAll';

        $.post(url, {userEmail:userEmail},function(data)
        {
             // alert(data);
             var returnedObje=data ;
             var situation_array_ddl=returnedObje.split(",");
             //  alert(situation_array.length);
             var sit_list_ddl='';
             for(var i=0;i<situation_array_ddl.length;i++)
                {
                        $situation_id_ddl=situation_array_ddl[i].split('#');
                        if(selectedSitId!=$situation_id_ddl[1])
                            sit_list_ddl+='<option id='+$situation_id_ddl[1]+' value="'+$situation_id_ddl[1]+'">'+$situation_id_ddl[0]+'</option>';
                }
                //sit_list_ddl+='</ul>';
                document.getElementById('sit_Id_copy').innerHTML=sit_list_ddl;
         });
    }
    var new_copy_name="";
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );

		var name = $( "#new_copy_name" ),
			allFields = $( [] ).add(name ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}

		$( "#copyContext" ).dialog({
			autoOpen: false,
			height: 450,
			width: 400,
			dialogClass: 'dialog_class',
			modal: true,
			buttons: {
				"Add": function() {
					document.getElementById('validation_copy').innerHTML="";
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

                                        bValid = bValid && checkLength( name, "new_copy_name", 3, 16 );
					//bValid = bValid && checkRegexp( sitName, /^[a-z]([0-9a-z_])+$/i, "Name may consist of a-z, 0-9, underscores, begin with a letter." );

					if ( bValid ) {
                                            var found='';
                                                for(var i=0;i<contexts.length;i++)
                                                    {
                                                        if(contexts[i].name==global_context_id_selected)
                                                        {
                                                            found=i;
                                                            break;
                                                        }
                                                    }
                                                if($("#type:checked").val()=="dublicate"){
                                                    //duplicate(context_id_cuting,target_situation_move);
                                                    //List_Contexts[i].situation_id=target_situation_move;
                                                    //List_Contexts[i].flag='duplicate';


                                                    var target_situation_move=$( "#sit_Id_copy" ).val();
                                                    var new_copy_name=$( "#new_copy_name" ).val();
                                                    $( this ).dialog( "close" );
                                                    var context_Id;
                                                    for(var i=0;i<contexts.length;i++)
                                                    {
                                                        if(contexts[i].name==global_context_id_selected)
                                                        {
                                                            context_Id=contexts[i].id;
                                                            cflag='duplicate_'+context_Id;
                                                            ctag=contexts[i].tags;
                                                            ccolor=contexts[i].color;
                                                        }
                                                    }
													alert(document.getElementById('o_'+global_context_id_selected).outerHTML);
                                                    var url='<?php echo base_url()?>view/duplicateContext';
$.post(url, {contextId:context_Id,sitId_to:target_situation_move,cHtml:document.getElementById('o_'+global_context_id_selected).outerHTML,
    cname:new_copy_name,cctag:ctag,ccflag:cflag,cccolor:ccolor,old_name:global_context_id_selected},function(data){
    //alert(data);
});

                                                }
                                                else
                                                {
                                                    var target_situation_move=$( "#sit_Id_copy" ).val();
                                                    var new_copy_name=$( "#new_copy_name" ).val();
                                                    $( this ).dialog( "close" );
                                                    var context_Id;
                                                    for(var i=0;i<contexts.length;i++)
                                                    {
                                                        if(contexts[i].name==global_context_id_selected)
                                                        {
                                                            context_Id=contexts[i].id;
                                                            cflag=contexts[i].flag;
                                                            ctag=contexts[i].tags;
                                                            ccolor=contexts[i].color;
                                                        }   
                                                    }
                                                    var url='<?php echo base_url()?>view/copyContext';
$.post(url, {contextId:context_Id,sitId_to:target_situation_move,cHtml:document.getElementById('o_'+global_context_id_selected).outerHTML,
    cname:new_copy_name,cctag:ctag,ccflag:cflag,cccolor:ccolor,old_name:global_context_id_selected});}
                                                }
                                                
				},
				Cancel: function() {

					$( this ).dialog( "close" );
					document.getElementById('validation_copy').innerHTML="";
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
				document.getElementById('validation_copy').innerHTML="";
			}
		});


	});
</script>

<div id="Div1" style="background-color: rgba(255, 255, 255, 0.609375); resize: none; overflow: auto;position:absolute;min-height:550px;width:1250px;-moz-border-radius:3px;border-radius:3px;box-shadow: inset 1px 1px 3px;border-color:silver;border-style:solid;border-width:1px" ><?php echo $html_sit; ?></div>

<script type="text/javascript">
    document.getElementById('Div1').style.height='<?php echo $height?>';
imgArray=document.getElementsByClassName("hideImg");
showCopyIcon = document.getElementsByClassName("copyClass");
divmod = document.getElementsByClassName("mod");
divContente = document.getElementsByClassName("hideOndb");
           for(j=0;j<showCopyIcon.length;j++)
           {
               $("#"+showCopyIcon[j].id).show();
               document.getElementById(showCopyIcon[j].id).style.left="5px";
               $("#"+divmod[j].id).hide();
               document.getElementById(divContente[j].id).setAttribute("ondblclick",null);
           }

          

            for (t = 0; t < imgArray.length; t++) {

                $("#"+imgArray[t].id).hide();
            }


</script>
</body>